<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/react.development.js"></script>
    <script src="js/react-dom.development.js"></script>
    <script src="js/babel.js"></script>
    <style>
        dl {
            margin: 0;
        }
        .friend-list {
            border: 1px solid #000000;
            width: 200px;
        }
        .friend-group dt {
            padding: 10px;
            background-color: rgb(64, 158, 255);
            font-weight: bold;
        }
        .friend-group dd {
            padding: 10px;
            display: none;
        }
        .friend-group.expanded dd {
            display: block;
        }
        .friend-group dd.checked {
            background: green;
        }
    </style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
let {useState,useEffect,useRef} = React;
function App(){
    let [val,setVal] = React.useState("");
    let [name,setName] = React.useState("");
    let oldName = useRef(name);
    useEffect(()=>{
        console.log("组件挂载之后");
        return ()=>{
            console.log("组件卸载之前");
        }
    },[]);
    useEffect(()=>{
        if(oldName.current !== name){
            console.log("组件更新");
            oldName.current = name;
        }
    },[name]);
    return (<div>
        <input 
            type="text" 
            value={val} 
            onChange={({target})=>{
                setVal(target.value);
            }}
        />
        <p>这前input的value是：{val}</p>
        <input 
            type="text" 
            value={name} 
            onChange={({target})=>{
                setName(target.value);
            }}
        />
        <p>这前name是：{name}</p>
    </div>)
}
ReactDOM.render(
    <App />, 
    document.querySelector("#root")
);
</script>      
</body>
</html>